package group.igfd.manager.biz.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import group.igfd.manager.biz.dao.CategoriesDao;
import group.igfd.manager.biz.entity.CategoriesEntity;
import group.igfd.manager.biz.service.CategoriesService;


@Service("categoriesService")
public class CategoriesServiceImpl extends ServiceImpl<CategoriesDao, CategoriesEntity> implements CategoriesService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<CategoriesEntity> page = this.selectPage(
                new Query<CategoriesEntity>(params).getPage(),
                new EntityWrapper<CategoriesEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public String getCategoryName(String categoryId) {

        try{
            Integer cId = Integer.valueOf(categoryId);
            CategoriesEntity categories = this.selectById(cId);
            if(null == categories)
                return categoryId;
            return categories.getName();
        }catch (Exception e){
            return categoryId;
        }
    }

}
